import time

from selenium.webdriver.common.by import By

from base.mp.base_page import BasePage, BaseOperate

"""
登录后主页
"""


class HomePage(BasePage):
    def __init__(self):
        super().__init__()
        self.nick = By.CSS_SELECTOR, ".user-name"
        self.content_manger = By.XPATH, "//*[@class='sidebar-el-menu el-menu']/div[2]/li/div"
        self.publish_article_btn = By.CSS_SELECTOR, ".el-menu--inline li"

    def find_nick(self):
        return self.get_element(self.nick)

    def find_content_manger_btn(self):
        return self.get_element(self.content_manger)

    def find_publish_article_btn(self):
        return self.get_element(self.publish_article_btn)


class HomeOperate(BaseOperate):
    def __init__(self):
        self.hp = HomePage()

    def get_nick(self):
        return self.hp.find_nick().text

    def click_content_manger_btn(self):
        self.hp.find_content_manger_btn().click()

    def click_publish_article_btn(self):
        self.hp.find_publish_article_btn().click()


class HomeBusiness:
    def __init__(self):
        self.op = HomeOperate()

    def get_user_nick(self):
        return self.op.get_nick()

    def go_publish_article_page(self):
        # 点击内容管理
        self.op.click_content_manger_btn()
        # 点击发布文章
        self.op.click_publish_article_btn()
        time.sleep(2)
